#!/usr/bin/env bash
# 
### BEGIN INIT INFO
# Provides:          PcapDNSProxyService
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Pcap_DNSProxy service
# Description:       Pcap_DNSProxy, a local DNS server based on Libpcap and WinPcap
### END INIT INFO
# 
# This code is part of Pcap_DNSProxy
# Pcap_DNSProxy, a local DNS server base on WinPcap and LibPcap
# Copyright (C) 2012-2018 Chengr28
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


# Global settings
NAME=Pcap_DNSProxy
PATH=
PROGRAM=/sbin/start-stop-daemon
START_FLAGS="--start --background --chuid root --exec"
STOP_FLAGS="--stop --chuid root --exec"

# Controller settings
case "$1" in
start)
	echo "Start Pcap_DNSProxy service."
	ulimit -n 10240
	$PROGRAM $START_FLAGS $PATH/$NAME --chdir $PATH
;;
stop)
	echo "Stop Pcap_DNSProxy service"
	$PROGRAM $STOP_FLAGS $PATH/$NAME
;;
force-reload|restart)
	echo "Force-reload/Restart Pcap_DNSProxy service."
	$PROGRAM $STOP_FLAGS $PATH/$NAME
	ulimit -n 10240
	$PROGRAM $START_FLAGS $PATH/$NAME --chdir $PATH
;;
status)
	echo
	/bin/ps -C Pcap_DNSProxy
	echo -e "\nPcap_DNSProxy is not running when PID is empty."
;;
*)
	echo "Usage: PcapDNSProxyService {start|stop|force-reload|restart|status}"
	exit 0
;;
esac
exit 0
